<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>xml http request format JSON parse</title>
  <script>
    window.onload = function () {
      let obtn = document.getElementById('btn')
      obtn.onclick = function () {
        let xhr = new XMLHttpRequest()
        xhr.open('GET', 'data/2.txt', false)
        xhr.send()
        xhr.onreadystatechange = () => {
          if (xhr.readyState === 4) {
            if (xhr.status >= 300 && xhr.status < 300 || xhr.status === 304) {
               let json = null 
               try {
                 json = JSON.parse(xhr.responseText)
               } catch (e) {
                 console.log(e)
                 json = eval(`(${xhr.responseText})`)
               }
            }
          }
        }
      }
    }
  </script>
</head>
<body>
  <input type="button" value="按钮" id="btn" />
</body>
</html>